package com.guoxin.artconcurrency.chapter3;

/**
 * @author guoxin
 * @date 2019/7/23
 */
public class DoubleCheckLocking {                           //1
    private static DoubleCheckLocking insetance;            //2

    private DoubleCheckLocking() {
    }

    public static DoubleCheckLocking getInstance() {        //3
        if (insetance == null) {                            //4：第一次检查
            synchronized (DoubleCheckLocking.class) {       //5.加锁
                if (insetance == null) {                    //6：第二次检查
                    insetance = new DoubleCheckLocking();   //7：问题的根源
                }                                           //8
            }                                               //9
        }                                                   //10
        return insetance;                                   //11
    }
}
